package com.nanhang.controller;

import com.nanhang.common.util.PageResult;
import com.nanhang.common.util.R;
import com.nanhang.entity.student;
import com.nanhang.vo.StudentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.nanhang.service.studentService;

import java.util.List;

@RestController
@RequestMapping("/student")
public class studentController {
    @Autowired
    private studentService studentService;
    @GetMapping("/list")
    public R findAll(){
        List<student> list = studentService.list();
        return R.ok().data("list",list);
    }
    // 分页查询
    @GetMapping("/findByPage/{page}/{pageSize}")
    public R findByPage(@PathVariable("page") Integer page,
                        @PathVariable("pageSize") Integer pageSize) {
        PageResult<student> pr = studentService.findByPage(page,pageSize);
        return R.ok().data("pr",pr);
    }
    // 条件带分页查询
    @PostMapping("/search/{page}/{pageSize}")
    public R search(@PathVariable("page") Integer page,
                    @PathVariable("pageSize") Integer pageSize,
                    @RequestBody(required = false) StudentVO vo){
        PageResult<student> pr = studentService.search(page,pageSize,vo);
        return R.ok().data("pr",pr);
    }
}

